#ifndef _SHARED_COMPONENT_TYPES_H_
#define _SHARED_COMPONENT_TYPES_H_

namespace Hiranipra {

	typedef struct HCMID_t {
		uint32 Data1;
		uint16 Data2;
		uint16 Data3;
		uint8 Data4[8];
	} HCMID;

	#define DEFINE_HCMID( name ) static const HCMID name

	INLINE bool Equals( const HCMID& a, const HCMID& b )
	{
		return
			( a.Data1 == b.Data1 ) && ( a.Data2 == b.Data2 ) && ( a.Data3 == b.Data3 ) &&
			( a.Data4[0] == b.Data4[0] ) && ( a.Data4[1] == b.Data4[1] ) && ( a.Data4[2] == b.Data4[2] ) && ( a.Data4[3] == b.Data4[3] ) &&
			( a.Data4[4] == b.Data4[4] ) && ( a.Data4[5] == b.Data4[5] ) && ( a.Data4[6] == b.Data4[6] ) && ( a.Data4[7] == b.Data4[7] );
	}

	
	#define HCMID_CC( x, l, r ) if( l != r ) x = l < r ? -1 : 1;
	INLINE int Compare( const HCMID& a, const HCMID& b )
	{
		int result = 0;
		HCMID_CC( result, a.Data1, b.Data1 );
		HCMID_CC( result, a.Data2, b.Data2 );
		HCMID_CC( result, a.Data3, b.Data3 );
		for( int n = 0; n < 8; n++ )
		{
			if( a.Data4[n] < b.Data4[n] )
				result = -1;
			if( a.Data4[n] > b.Data4[n] )
				result =  1;
		}
		return result;
	}

	INLINE uint32 Hash( const HCMID& hcmid )
	{
		uint32 hash = 0;
		for( uint32 n = 0; n < 8; n++ )
			hash ^= ( (const short *)&hcmid )[ n ];
		return hash & 0x1F;
	}

	struct LessHCMID : public binary_function<HCMID, HCMID, bool>
	{
		bool operator()( const HCMID& _Left, const HCMID& _Right ) const
		{
			return Compare( _Left, _Right ) < 0;
		}
	};

	struct CompareHCMID : public binary_function<HCMID, HCMID, int>
	{
		int operator()( const HCMID& _Left, const HCMID& _Right ) const
		{
			return Compare( _Left, _Right );
		}
	};

}

#endif // _SHARED_COMPONENT_TYPES_H_
